package controles;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import fenetres.*;

public class AccueilMenuAction implements ActionListener{

	//private AuthentificationFrame authentFrame;
	Accueil accueil ;
	
	public AccueilMenuAction(Accueil _accueil){
		this.accueil = _accueil;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == accueil.connexMenu){
			this.accueil.authent = new AuthentificationFrame (accueil);
			this.accueil.authent.setVisible(true); 
	        accueil.desktop.add(this.accueil.authent);
	       
	        try {
	        	this.accueil.authent.setSelected(true);
	        } catch (java.beans.PropertyVetoException ex) {}
	       
		}
		
	
		if(e.getSource() == accueil.deconnexMenu){
			
			String message = ""+accueil.userConnected.getNom()+" , vous etes deconnetes ! \n Bye!!!";
			JOptionPane.showMessageDialog(null,message ,"Confirmation",JOptionPane.INFORMATION_MESSAGE);
			accueil.authent.userConnected = null;
		}
		

		if(e.getSource() == accueil.exitMenu){
			System.exit(0);
			
		}
		
		if(e.getSource() == accueil.addProdMenu){
			if(accueil.authent != null) accueil.userConnected = accueil.authent.getUserConnected();
			AddProdFrame addProdFrame = new AddProdFrame(accueil.userConnected);
			addProdFrame.setVisible(true); 
			accueil.desktop.add(addProdFrame);
	        try {
	        	addProdFrame.setSelected(true);
	        } catch (java.beans.PropertyVetoException ex) {}
		}
		
		if(e.getSource() == accueil.listProdMenu){
			if(accueil.authent != null) accueil.userConnected = accueil.authent.getUserConnected();
			ListProduitFrame listProdFrame = new ListProduitFrame(accueil.userConnected);
			listProdFrame.setVisible(true); 
			accueil.desktop.add(listProdFrame);
	        try {
	        	listProdFrame.setSelected(true);
	        } catch (java.beans.PropertyVetoException ex) {}
		}
		
		if(e.getSource() == accueil.addFrsMenu){
			if(accueil.authent != null) accueil.userConnected = accueil.authent.getUserConnected();
			AddSupplierFrame addSupplierFrame = new AddSupplierFrame(accueil.userConnected);
			addSupplierFrame.setVisible(true); 
			accueil.desktop.add(addSupplierFrame);
	        try {
	        	addSupplierFrame.setSelected(true);
	        } catch (java.beans.PropertyVetoException ex){}
		}
		
		if(e.getSource() == accueil.updateFrsMenu){
			if(accueil.authent != null) accueil.userConnected = accueil.authent.getUserConnected();
			ChoiceSupplierFrame choiceSupplierFrame = new ChoiceSupplierFrame (accueil.userConnected, accueil);
			choiceSupplierFrame.setVisible(true); 
			accueil.desktop.add(choiceSupplierFrame);
	        try {
	        	choiceSupplierFrame.setSelected(true);
	        } catch (java.beans.PropertyVetoException ex) {}
		}
		//information sur les stocks
		if(e.getSource() == accueil.infoStockMenu){
			if(accueil.authent != null) accueil.userConnected = accueil.authent.getUserConnected();
			ChoiseStockFrame choiseStockFrame = new ChoiseStockFrame(accueil.userConnected, accueil);
			choiseStockFrame.setVisible(true); 
			accueil.desktop.add(choiseStockFrame);
	        try {
	        	choiseStockFrame.setSelected(true);
	        } catch (java.beans.PropertyVetoException ex) {}
		
		}
		if(e.getSource() == accueil.addProdStockMenu){
			if(accueil.authent != null) accueil.userConnected = accueil.authent.getUserConnected();
			AddProductStockFrame addProductStockFrame = new AddProductStockFrame(accueil.userConnected, accueil);
			addProductStockFrame.setVisible(true); 
			accueil.desktop.add(addProductStockFrame);
	        try {
	        	addProductStockFrame.setSelected(true);
	        } catch (java.beans.PropertyVetoException ex) {}
		
		}
		
		if(e.getSource() == accueil.traceStockMenu){
			if(accueil.authent != null) accueil.userConnected = accueil.authent.getUserConnected();
			ListOperationFrame listOperationFrame = new ListOperationFrame(accueil.userConnected, accueil);
			listOperationFrame.setVisible(true); 
			accueil.desktop.add(listOperationFrame);
	        try {
	        	listOperationFrame.setSelected(true);
	        } catch (java.beans.PropertyVetoException ex) {}
		
		}
	}
}
